export const handleDownload = function(url) {
    let fileName = new Date().valueOf();
    uni.downloadFile({
      url: url,
      filePath: uni.env.USER_DATA_PATH + '/' + fileName + '.mp4',
      success: res => {
        console.log(res);
        let filePath = res.filePath;
        uni.saveVideoToPhotosAlbum({
          filePath,
          success: file => {
            uni.showToast({
              title: '下载成功',
              icon: 'success',
              duration: 2000
            })
            let fileMgr = uni.getFileSystemManager();
            fileMgr.unlink({
              filePath: uni.env.USER_DATA_PATH + '/' + fileName + '.mp4',
              success: function (r) {

              },
            })
          },
          fail: err => {
            console.log(err)
            if (err.errMsg === 'saveVideoToPhotosAlbum:fail auth deny') {
              uni.showModal({
                title: '提示',
                content: '需要您授权保存相册',
                showCancel: false,
                success: data => {
                  uni.openSetting({
                    success(settingdata) {
                      if (settingdata.authSetting['scope.writePhotosAlbum']) {
                        uni.showModal({
                          title: '提示',
                          content: '获取权限成功,再次点击下载即可保存',
                          showCancel: false,
                        })
                      } else {
                        uni.showModal({
                          title: '提示',
                          content: '获取权限失败，将无法保存到相册哦~',
                          showCancel: false,
                        })
                      }
                    },
                  })
                }
              })
            }
          }
        })
      }
    })
  }
  
  
